package com.itheima.d10_api_object;

import com.itheima.d10_api_object.bean.User;

public class Test2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        // 目标：掌握Object类提供的对象克隆的方法。
        // 1、protected Object clone()：对象克隆。

        User u1 = new User(1, "zhangsan", "wo666", new double[]{99.0, 99.5});
        System.out.println("u1 = " + u1);

        //克隆u1对象，得到新的对象
        //步骤：
        //1 先让User实现接口 Cloneable
        //2 public权限重写clone方法
        //3 调用clone方法克隆对象

        User u2 =  u1.clone();
        System.out.println(u1==u2);//false u2和u1不是同一个对象
        System.out.println("u2 = " + u2);
        //浅克隆
        //u1 = User{id=1, username='zhangsan', password='wo666', scores=[D@30f39991}
        //u2 = User{id=1, username='zhangsan', password='wo666', scores=[D@30f39991}

        //深克隆
        //u1 = User{id=1, username='zhangsan', password='wo666', scores=[D@30f39991}
        //u2 = User{id=1, username='zhangsan', password='wo666', scores=[D@452b3a41}

    }
}
